import wepy from 'wepy'

export default class extends wepy.mixin {
  data = {
    catesList: [],
    activeKey: 0,
    wh: 0,
    secondCate: []
  }

  onLoad() {
    this.getCatesList()
    this.getWindowHeight()
  }

  methods = {
    onChange(e) {
      this.secondCate = this.catesList[e.detail].children
    },
    goGoodsList(cid){
      wepy.navigateTo({
        url: '/pages/goods_list?cid='+cid
      })
    }
  }

  async getCatesList() {
    const { data: res } = await wepy.get('/categories')
    if (res.meta.status !== 200) {
      return wepy.baseToast()
    }
    this.catesList = res.message
    this.secondCate = this.catesList[0].children
    this.$apply()
  }

  async getWindowHeight() {
    const systemInfo = await wepy.getSystemInfo()
    if (systemInfo.errMsg === 'getSystemInfo:ok') {
      this.wh = systemInfo.windowHeight
      this.$apply()
    }
  }
}
